package cn.lb.basic.service.impl;

import cn.lb.basic.query.BaseQuery;
import cn.lb.basic.mapper.BaseMapper;
import cn.lb.basic.service.IBaseService;

import cn.lb.basic.util.PageList;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;

@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {
    @Autowired
    private BaseMapper<T> baseMapper;


    @Transactional
    @Override
    public void insert(T t) {
        baseMapper.insert(t);
    }

    @Transactional
    @Override
    public void deleteById(Serializable id) {
baseMapper.deleteById(id);
    }
    @Transactional
    @Override
    public void update(T t) {
baseMapper.update(t);
    }

    @Override
    public T selectById(Serializable id) {
        return baseMapper.selectById(id);
    }

    @Override
    public List<T> selectAll() {
        return baseMapper.selectAll();
    }

    @Override
    public PageList<T> page(BaseQuery query) {
        Long total=baseMapper.querytotal(query);
        if (total>0){
            List<T> queryrows = baseMapper.queryrows(query);
            return new PageList<T>(queryrows,total);
        }
        return new PageList<T>();
    }
    @Transactional
    @Override
    public void deletebatch(List<Long> ids) {

    }
}
